- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.4k
          [Jackson 3] Fix #3580 Enum (de)serialization in conjunction with JsonFormat.Shape.NUMBER_INT
          #5338
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Conversation
| @JooHyukKim This seems incomplete? Or maybe diff is missing something due to conflict? | 
| @cowtowncoder Yes, there were some other commits on same file, affecting this PR. THankss | 
| Ready for review! Just in case I wasn't clear enough | 
|  | ||
| /** | ||
| * We may also have integer-type of representation for Enum's, along with `@JsonValue`. | ||
| * | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Since 3.1
        
          
                src/main/java/tools/jackson/databind/deser/jdk/EnumDeserializer.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      | */ | ||
| protected final boolean _isShapeNumberInt; | ||
|  | ||
| public EnumDeserializer(EnumResolver byNameResolver, boolean caseInsensitive, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to start deprecating methods, adding overloads (since it's 3.1, not 3.0)
        
          
                src/main/java/tools/jackson/databind/deser/BasicDeserializerFactory.java
          
            Show resolved
            Hide resolved
        
      There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| return null; | ||
| } | ||
| if (format.getShape() != JsonFormat.Shape.NUMBER_INT) { | ||
| throw new IllegalArgumentException("Failed to access @JsonValue of Enum value "); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this return null? Also, could perhaps also allow Shape.NUMBER.
| * Method used when ALL of conditions below are met | ||
| *<p> | ||
| * 1. actual String serialization is indicated using @JsonValue on a method in Enum class AND | ||
| * 2. Enum class is annotated with `@JsonFormat` | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... with shape = Shape.NUMBER_INT ?
| * 2. Enum class is annotated with `@JsonFormat` | ||
| * | ||
| */ | ||
| public static EnumResolver constructUsingNumberShape(DeserializationConfig config, AnnotatedClass annotatedClass, AnnotatedMember accessor) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add Javadoc to explain what accessor is for... @JsonValue annotated thing?
| for (int i = enumConstants.length; --i >= 0; ) { // from last to first, so that in case of duplicate values, first wins | ||
| Enum<?> en = enumConstants[i]; | ||
| try { | ||
| Object o = accessor.getValue(en); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is being accessed here?
No description provided.